package ca.camosun.bouncer.tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import ca.camosun.bouncer.game.Paddle;

public class PaddleTest {

	Paddle squarePaddle;
	Paddle tallPaddle;
	Paddle widePaddle;

	@Before
	public void setUp() throws Exception {
		squarePaddle = new Paddle(12, 12);
		tallPaddle = new Paddle(10, 30);
		widePaddle = new Paddle(30, 10);
	}

	@Test
	public void playUntilGameOver() {
		squarePaddle.attemptBounce(4, 0, 10);
		assertTrue(squarePaddle.isBallInPlay() == true);
		assertTrue(squarePaddle.getTotalAccumulatedHeight() == 10);

		squarePaddle.attemptBounce(0, 2, 5);
		assertTrue(squarePaddle.isBallInPlay() == true);
		assertTrue(squarePaddle.getTotalAccumulatedHeight() == 15);

		squarePaddle.attemptBounce(4, 0, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);
		assertTrue(squarePaddle.getTotalAccumulatedHeight() == 15);
	}

	@Test
	public void ballCanFallOffRightOfBoard() {
		squarePaddle.attemptBounce(7, 1, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);
	}

	@Test
	public void ballCanFallOffLeftOfBoard() {
		squarePaddle.attemptBounce(-7, 1, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);
	}

	@Test
	public void ballCanFallOffTopOfBoard() {
		squarePaddle.attemptBounce(1, 7, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);
	}

	@Test
	public void ballCanFallOffBottomOfBoard() {
		squarePaddle.attemptBounce(1, -7, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);
	}

	@Test
	public void ballDidNotFallOffBoard() {
		squarePaddle.attemptBounce(4, 1, 10);
		assertTrue(squarePaddle.isBallInPlay() == true);

		tallPaddle.attemptBounce(4, 9, 10);
		assertTrue(tallPaddle.isBallInPlay() == true);

		widePaddle.attemptBounce(8, 1, 10);
		assertTrue(widePaddle.isBallInPlay() == true);
	}

	@Test
	public void ballFallsOffForDifferentPaddleSizes() {
		squarePaddle.attemptBounce(5, 9, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);

		squarePaddle.attemptBounce(8, 1, 10);
		assertTrue(squarePaddle.isBallInPlay() == false);
	}

}
